package com.developer.platform.application.query.assembler;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.application.query.dto.TemplateDto;
import com.developer.platform.domain.Template;
import java.util.stream.Collectors;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class TemplateAssembler {

  public ResponseModel<TemplateDto> toTemplateDtoPage(IPage<Template> page){
    return new ResponseModel<>(page.getRecords().stream().map(template -> {
      TemplateDto templateDto = new TemplateDto();
      BeanUtil.copyProperties(template, templateDto);
      return templateDto;
    }).collect(Collectors.toList()), (int)page.getTotal());
  }

}
